Razor basic syntax 1: Razor basic syntax
Directory:
What is Razor?
Rendering HTML
Razor syntax
Implicit Razor expression
Explicit Razor expression
What is Razor?
First, Razor grammar1. Razor identifierExplanation: The @ character is defined as the identifier of the Razor server code block, followed by the server code. It is a good idea to use @{ String userName = "Kai Super"; span > My name is: @userNamespan> span > My date of birth: @DateTime. Now.tostring ("Yyyy-mm-dd"); span >
Razor, razor
When learning MVC, you will always see the default Razor when creating a controller:
Then, we can write the following in the created View:
So what are the things with @ That don't look like html but put on The View? Let's start from the beginning ~~
1. What is Razor
Razor Exercise 4, razor exercise
Practice Razor's logic processing today. Generally, the following
1. if
2. else
3. else if
4. switch
In the following demonstration, Insus. NET demonstrates 1, 2, and 4 respectively:The xxx. cshtml code is as follows:@ {Layout = null; string laborDay = ""; string name = "Insus. NET "; string [] colors = {" ff0000 "," 0000ff "," 00ff00 "}; // red, blue, green} Animation demo
The key is to output JS on the plain text content, so that the browser to parse the JS code@: Indicates the direct output string afterEither way, note that MVC Razor with JavaScript (embedded razor in JS)
Razor and razorPreface:
The core of the Razor engine is to identify the @ symbol and angle brackets:1. 2. [For more information, see the example below.]
@for (int i = 0; i
{
}
Basic Syntax: Syntax 1 ,@()
Expression
@ (1 = 0? "1 equals 0": "1 not equal to 0 ")
Syntax 2 ,@{}
Statement Block
@{
var now = DateTime.Now;
if (now.Hour.CompareTo(12)
{
}
else
{
}
}
Use ajax to partially update the Razor page and ajax to partially update the razor page
Razor is very powerful, but it cannot be refreshed. Therefore, it must be used with ajax.
This article provides a simple example to achieve local refresh through Razor and ajax.
First, create an MVC Project
Let's create a simple Co
Some methods of link in Razor syntax, razor syntax Link
In Razor, there are HTML. ActionLink and Url. Action to render the link. What are their differences. If you can clearly distinguish them, you will know under what circumstances to use them.First, let's take a look at html. ActionLink. This method loads a lot and generates a If no controller is specified, the
Razor Exercise 2, razor exercise
Razor data types include string, int, float, decimal, and bool.In addition, data type conversion is required. The common methods are as follows:ToString (): converts the data type to string ). This is the same as the C # syntax.IsBool () and AsBool () convert strings to Boolean values ).IsFloat () and AsFloat () convert strings t
Razor Exercise 3, razor exercise
In Razor syntax, it uses three types of material loop processing: for, while, and foreach.
The following Insus. NET illustrates an example in the ASP. net mvc environment by appending the source code:While: Animation demonstration:
Forced conversion of the razor type and forced conversion of the razor type
1. If the background obtains a List type
1. Obtain array data in the background
Var dutyList = IOCFactory. R ViewBag. dutyList = dutyList;
2. Front-end cyclic binding drop-down box
@ Foreach (Object item in ViewBag. dutyList){}
2. If the backend obtains a List
1. Obtain the object array type in the background
List ViewBag. dutyLis
Tags: book title Update name Create Project class MEP get fieldLearn the ASP. NET Core Razor Programming series Catalog Learn ASP. NET Core Razor programming series One Learn ASP. NET Core Razor Programming series two--Add an entity Learn ASP. NET Core Razor Programming series three--Create a data table and create a pr
ASP. NET Core Chinese Document Chapter 4 MVC (3.2) Razor syntax reference, mvcrazor
Original article: Razor Syntax ReferenceBy Taylor Mullen and Rick AndersonTranslation: Liu Yi (AlexLEWIS)Proofreader: He zhenghouWhat is Razor?
Razor is a tag syntax that can be converted to web pages based on server code. The
Original: Razor Syntax ReferenceTaylor Mullen, Rick AndersonTranslation: Liu Yi (alexlewis)Proofreading: He ShiodomeWhat is Razor?Razor is a markup syntax that can be converted to a Web page based on server-side code. The Razor syntax consists of Razor tags, C #, and HTML. F
The main design goal of Razor syntax is to allow code and tag streams to work together while minimizing conflict with control characters. For example, the following ASPX code:
Now, we leave only what we actually care about, remove the extra ASPX control characters, and the following code is processed:
foreach(var p in Model.Products) { }
Obviously, the above code doesn't have enough information to decide which
I'm sure you've all tried nesting JavaScript in a View, and you can use the Razor syntax directly to invoke some of the. NET methods. The following code is nested in a Razor View:
But the other thing is, if I want to use Razor in a standalone JS file, the above method will not work, because MVC does not directly explain JS file, only put in
Transferred from: http://kb.cnblogs.com/page/102191/ASP. NET MVC 3 supports a new view engine option named "Razor" (in addition to continuing to support/strengthen the existing. aspx view engine). When writing a view template, razor minimizes the number of characters and keystrokes required and guarantees a fast, unobstructed coding workflow.Unlike most templates, with the help of
reloading a Razor WebGrid after Ajax calls using a partial viewThe If you is using Razor and MVC probably make some use of the built in controls in System.Web.Helpers. WebGrid, located in the Helpers assembly, is created for WebMatrix's Razor Web Pages and landed itself nicely to Razor VI EWS in MVC. WebGrid, much li
The two almost do not understand, now to choose one, only Baidu, and then a look, do not know which of you big God said right.Two engine syntax is completely different, the performance of ASP. NET Advantage, syntax sugar is Razor's strength.Development MVC3 Preferred RazorRazor is the mainstream. Not the same syntax.Razor SimplicityCshtml using razor rendering engineaspx using WebForm engineDifferent syntaxThe two files are inserted into the ASP tag i
Razor front, must be with the front of the gap, that is, the space, after the need to be coherent, otherwise add parentheses1, when outputting a single variable in the page, simply precede the C # statement with the @ symbol.For example1 2 present moment: @DateTime. Now3 2, if you want to output a paragraph containing a blank word or word operation results, you must add a parenthesis before and after1 2 member name: @ (viewbag.isenabled?" ) en
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.